package it.evento.utils.genpage;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author Ilo
 */
public class Article {
    
    private String title;
    private String content;
    private List<ArticleRow> rows;

    public Article() {
        resetAll();
    }

    public Article setTitle(String title) {
        this.title = title;
        return this;
    }
    
    public Article setContent(String content) {
        this.content = content;
        return this;
    }

    public Article setRows(List<ArticleRow> rows) {
        this.rows = rows;
        return this;
    }
    public Article setRows(ArticleRow[] rows) {
        List<ArticleRow> list = new LinkedList<>();
        list.addAll(Arrays.asList(rows));
        return setRows(list);
    }
    
    public String print() {
        String ret = "";
        
        ret += "<article class='evento-post evento-article'>";
            if(this.title != null) {
                ret += "<div class='evento-postmetadataheader'>";
                    ret += "<h2 class='evento-postheader'>" + this.title + "</h2>";
                ret += "</div>";
            }

            ret += "<div class='evento-postcontent evento-postcontent-0 clearfix'>";
                if(!this.content.equals("") && !this.rows.isEmpty()) {
                    ret += this.content;
                    for(ArticleRow row : this.rows) {
                        ret += row.print();
                    }
                }
                else if(this.content.equals("")) {
                    for(ArticleRow row : this.rows) {
                        ret += row.print();
                    }
                }
                else if(this.rows.isEmpty()) {
                    ret += this.content;
                }
                else {
                    ret += "";
                }
            ret += "</div>";
        ret += "</article>";
        
        resetAll();
        
        return ret;
    }
    
    private void resetAll() {
        this.title = null;
        this.content = "";
        this.rows = new LinkedList<>();
    }
    
}
